package com.ynkbny.web.controller;

import com.ynkbny.domain.dto.FormulaConfigurationAddDTO;
import com.ynkbny.domain.pojo.FormulaConfigurationArgumentVO;
import com.ynkbny.service.FormulaConfigurationService;
import com.ynkbny.util.Res;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 公式配置相关接口v2
 * @Author YY
 * @Date 2023/9/4 20:36
 */
@Slf4j
@Api(tags = "公式配置相关接口v2")
@RestController
@RequestMapping("/FormulaConfiguration")
public class FormulaConfigurationController {

    @Resource
    private FormulaConfigurationService formulaConfigurationService;

    /**
     * 添加公式
     * @param formulaConfigurationAddDTO FormulaConfigurationAddDTO
     * @Author YY
     */
    @ApiOperation("添加公式")
    @PostMapping("/save")
    public Res<Object> saveFormula(@RequestBody FormulaConfigurationAddDTO formulaConfigurationAddDTO){
        log.info("添加公式-请求参数：{}",formulaConfigurationAddDTO);
        boolean add = formulaConfigurationService.add(formulaConfigurationAddDTO);
        log.info("添加公式-返回值：{}",add);
        return Res.ok(add);
    }

    /**
     * 修改公式
     * @param formulaConfigurationAddDTO FormulaConfigurationAddDTO
     * @Author YY
     */
    @ApiOperation("修改公式")
    @PostMapping("/update")
    public Res<Object> updateFormula(@RequestBody FormulaConfigurationAddDTO formulaConfigurationAddDTO){
        log.info("修改公式-请求参数：{}",formulaConfigurationAddDTO);
        boolean update = formulaConfigurationService.update(formulaConfigurationAddDTO);
        log.info("修改公式-返回值：{}",update);
        return Res.ok(update);
    }

    /**
     * 删除公式
     * @Author YY
     * @param dataCollectConfigureId 采集配置项id
     */
    @ApiOperation("删除公式")
    @PostMapping("/delete")
    public Res<Object> deleteFormula(@RequestParam("dataId") String dataCollectConfigureId){
        log.info("删除公式-请求参数：{}",dataCollectConfigureId);
        Res<Object> delete = formulaConfigurationService.delete(dataCollectConfigureId);
        log.info("删除公式-返回值：{}",delete);
        return delete;
    }

    /**
     * 查询公式列表
     * @Author YY
     * @param enterpriseCode 企业统一信用代码
     * @return Res.ok(list)
     */
    @ApiOperation("查询公式列表")
    @PostMapping("/select/a")
    public Res<Object> selectFormulaList(@RequestParam("enterpriseCode") String enterpriseCode){
        log.info("查询公式列表-请求参数：{}",enterpriseCode);
        List<FormulaConfigurationArgumentVO> list = formulaConfigurationService.selectFormulaList(enterpriseCode);
        log.info("查询公式列表-返回值：{}",list);
        return Res.ok(list);
    }

    /**
     * 查询一个公式
     * @Author YY
     * @param dataCollectConfigureId 采集配置项id
     * @return Res<Object>
     */
    @ApiOperation("查询一个公式")
    @PostMapping("/select/getOne")
    public Res<Object> selectFormula(@RequestParam("dataId") String dataCollectConfigureId){
        log.info("查询一个公式-请求参数：{}",dataCollectConfigureId);
        FormulaConfigurationAddDTO formulaConfigurationAddDTO = formulaConfigurationService.getOneFormula(dataCollectConfigureId);
        log.info("查询一个公式-返回值：{}",formulaConfigurationAddDTO);
        return Res.ok(formulaConfigurationAddDTO);
    }
}
